<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
li {width:400px; height:100px; border-bottom:1px solid #333;}
</style>
<script>
window.onload = function (){
  var oUl = document.getElementById('list');
  var aLi = oUl.getElementsByTagName('li');
/*  
  for (var i=0;i<aLi.length;i++){
   aLi[i].onclick = function (){alert(1);};
   //aLi[i].onclick = function (){alert(i);};
  }
*/
  //如果想弹出当前索引，需要运用到闭包的知识
  for (var i = 0; i < aLi.length; i++) {
      aLi[i].onclick = (function (i){
      	return function(){
      		alert(i)
      	}
      })(i)

  };
}
</script>
</head>
<body>
<ul id="list">
  <li></li>
  <li></li>
  <li></li>
  <li></li>
</ul>
</body>
</html>
